package com.itheima.pinda.config;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.itheima.pinda.common.utils.IdWorker;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 自定义 mp的主键id生成器, 实体属性设置为 @TableId(value = "id", type = IdType.INPUT)
 *
 * @author llhuang10
 * @date 2021/9/29 15:19
 */
@Component
public class CustomIdGenerator implements IdentifierGenerator {


    @Resource
    private IdWorker idWorker;

    @Bean
    public IdWorker idWorker() {
        return new IdWorker(1, 1);
    }

    /**
     * 生成唯一id
     */
    @Override
    public Number nextId(Object entity) {
        return idWorker.nextId();
    }
}
